package com.zzq.my.jetpacks.jectpackapp.net.submitfeedback

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.aisier.architecture.base.BaseViewModel
import com.aisier.network.observer.StateLiveData
import com.zzq.my.jetpacks.net.rxhttp.show
import kotlinx.coroutines.launch

/**
 * 描述：意见反馈参数+图文一起上传
 * 作者：zhuangzeqin
 * 时间: 2022/1/20-14:16
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class SubmitFeedbackViewModel : BaseViewModel() {
    private val mRepository by lazy { SubmitFeedbackRepo() }

    val submitFeedbackLiveData = StateLiveData<String>()
    val submitFeedbackLiveData2 = MutableLiveData<String>()

    fun submitFeedback(
        problemType: String,
        complainterType: String,
        content: String,
        mobileNo: String,
        filePaths: List<String>
    ) {
        //启动一个协程的
        viewModelScope.launch {
            submitFeedbackLiveData.value =  mRepository.submitFeedback(problemType, complainterType, content, mobileNo, filePaths)
        }

    }


    fun submitFeedback2(
        problemType: String,
        complainterType: String,
        content: String,
        mobileNo: String,
        filePaths: List<String>
    ) {
        //启动一个协程的
        viewModelScope.launch {
            mRepository.submitFeedbackRxHttp(problemType, complainterType, content, mobileNo, filePaths).apply {
                onSuccess {
                    submitFeedbackLiveData2.value = it
                }
                onFailure {
                    it.show()
                }
            }
        }

    }

}